package com.hmall.user.itercepter;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author:luoyong
 * Date:2021/11/8 17:04
 */
@Component
public class MyIntercepter implements HandlerInterceptor {

    public static ThreadLocal<String> threadLocal = new ThreadLocal();

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("preHandle");

        String userId = request.getHeader("authorization");

        if (userId != null) {
            threadLocal.set(userId);
        }

        return true;
    }

}
